import share from '@/libs/share/index';
import store from '@/store';
export default {
	onLoad(options) {
		share.setShareInfo();
	},

	// #ifdef MP-WEIXIN
	onShareAppMessage(res) {
		let that = this;
		let shareInfo = store.getters.shareInfo;
		console.log('shareInfo', shareInfo);
		return {
			title: shareInfo.title,
			path: shareInfo.path,
			imageUrl: shareInfo.image,
			success(res) {
				uni.showToast({
					title: '分享成功',
				});
			},
			fail(res) {
				uni.showToast({
					title: '分享失败',
					icon: 'none',
				});
			},
			complete() {},
		};
	},
	onShareTimeline(res) {
		let that = this;
		let shareInfo = store.getters.shareInfo;
		let query = shareInfo.query;
		//携带当前页面资源ID参数
		let currentPage = getCurrentPages()[getCurrentPages().length - 1];
		let options = currentPage.options;
		if (JSON.stringify(options) != '{}' && options.id) {
			query += `&id=${options.id}`;
		}

		return {
			title: shareInfo.title,
			query: query,
			imageUrl: shareInfo.image,
			success(res) {
				uni.showToast({
					title: '分享成功',
				});
			},
			fail(res) {
				uni.showToast({
					title: '分享失败',
					icon: 'none',
				});
			},
			complete() {},
		};
	},
	// #endif
};
